home *** CD-ROM | disk | FTP | other *** search
- /* Copyright 1992 H.Ogasawara(COR.) */
-
- #include <stdio.h>
- #include <wlib.h>
- #include "proto.h"
- #include "run.h"
-
- #define SIZEH (6*24)
- #define SIZEV (30)
- #define COUNTX (2+30)
- #define COUNTY (12+2+2)
- #define FNAMEX (2)
- #define FNAMEY (2)
-
- /*
- Xsm X/Y Y-G
-
- Xsum-Send:
- [Mode] [Receive] [Exit]
-
- Xsum-Send: denden.pro
- 0000K (0000/0000) [Cancel]
-
- Receive: program.ttt
- [Y-G] 0000K ( 0/ 0)
- */
-
- unsigned int timeout;
- unsigned short runsize;
- void (*run)();
-
- unsigned int size;
- unsigned short block,
- last;
-
- unsigned short autoexit= FALSE,
- batch= FALSE,
- sendflag= FALSE;
-
- WindowID Awp= NULL;
-
- int WindowHeapSize= 0*1024;
-
- DispSet( dbuf )
- DrawBuf *dbuf;
- {
- static unsigned char buf[]= {
- /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 */
- ' ',' ',' ',' ','K',' ','(',' ',' ',' ','0','/',' ',' ',' ','0',')','\0'
- };
- unsigned char *str= buf+4;
- unsigned short i= size/1024;
- do{
- *--str= i%10+ '0';
- }while( i/= 10 );
- for(; str > buf ; *--str= ' ' );
- str= buf+11;
- i= block;
- do{
- *--str= i%10+ '0';
- }while( i/= 10 );
- for(; str > buf+7 ; *--str= ' ' );
- str= buf+16;
- i= last;
- do{
- *--str= i%10+ '0';
- }while( i/= 10 );
- for(; str > buf+12 ; *--str= ' ' );
- DrawSetSymbol( dbuf, COUNTX, COUNTY, (char*)buf, 9, 12 );
- return 1;
- }
-
- DispFileSet( dbuf )
- DrawBuf *dbuf;
- {
- /*Y-Receive: program.ttt*/
- static char buf[50];
- static char *mode[]= { "[Xsm]", "[X/Y]", "[Y-G]",
- "[???]", "[Y-B]", "[YGB]",
- "[ X ]", "[X-L]", "[ Y ]\0Copyright 1992 H.Ogasawara(COR.)" };
- strcpy( buf, sendflag ? "Send: " : "Receive: " );
- strcat( buf, sendflag && !*filename ? "ファイル名?" :(char*)filename);
- strcat( buf, " " );
- DrawSetSymbol( dbuf, FNAMEX, FNAMEY, buf, 9, 12 );
- DrawSetSymbol( dbuf+1, COUNTX-30, COUNTY, mode[ sendflag ? rettype+6 : batch ? rettype+3 : rettype ], 9, 12 );
- return 2;
- }
-
- DispFilename()
- {
- DrawBuf dbuf[2];
- WindowDraw( Awp, dbuf, DispFileSet( dbuf ) );
- }
-
- DispCountup()
- {
- DrawBuf dbuf[1];
- WindowDraw( Awp, dbuf, DispSet( dbuf ) );
- }
-
- EndProgram()
- {
- if( autoexit )
- WindowSendSignal( WindowProcessID, SignalKill, NULL );
- }
-
- Exec( wp, info )
- WindowID wp;
- EventInfo *info;
- {
- DrawBuf dbuf[8];
- static unsigned char retbuf[2048],
- *retptr= retbuf;
- static unsigned short retsize= 0;
- switch( info->option ){
- case EventInterval:
- if( runsize && ISNS232C() ){
- do{
- *retptr++= INP232C();
- if( ++retsize >= runsize ){
- (*run)( retbuf );
- retsize= 0;
- retptr= retbuf;
- return TRUE;
- }
- }while( ISNS232C() );
- return TRUE;
- }else if( timeout && ONTIME() >= timeout ){
- (*run)( NULL );
- return TRUE;
- }
- return FALSE;
- case EventOpen:
- WindowSetEventAttr( Awp= wp, EventOpenON|EventCloseON|
- EventKeyON|EventUserON|
- EventRedrawON|EventMouseSwitchON|EventIntervalON );
- WindowRedraw( wp );
- if( autoexit ){
- if( sendflag ){
- if( *filename )
- SendStart();
- }else
- ReceiveStart();
- }
- return TRUE;
- case EventRedraw:
- DrawSetClear( dbuf, 1 );
- DispSet( dbuf+1 );
- DispFileSet( dbuf+2 );
- WindowDraw( wp, dbuf, 4 );
- return TRUE;
- case EventClose:
- CloseFile();
- if( autoexit ){
- unsigned int pid;
- if( pid= PidSearch( "k20.win", 1 ) ){
- info->option= EventUser;
- info->ComData= 'k20';
- info->ComBuffer= "i1";
- WindowSendEventAll( pid, info );
- }
- }
- WindowClose( wp );
- WindowConnectionClose();
- return TRUE;
- case EventMouseSwitch:
- return TRUE;
- case EventKey:
- if( info->KeyCode == 3 || info->KeyCode == ('x'&0x1f) ){
- Write232C( CAN );
- Write232C( CAN );
- Write232C( CAN );
- Write232C( CAN );
- allbreak();
- }
- return TRUE;
- case EventUser:
- if( sendflag && !*filename ){
- switch( info->ComData ){
- case UserPaste:
- case UserString:
- strcpy( filename, info->ComBuffer );
- DispFilename();
- SendStart();
- break;
- case UserStrings:
- strcpy( filename, *(char**)info->ComBuffer );
- DispFilename();
- SendStart();
- break;
- }
- }
- return TRUE;
- }
- return FALSE;
- }
-
- WindowMain( argc, argv )
- char **argv;
- {
- int x= 80,
- y= 80;
- *filename= '\0';
- argc= AnalyzeArgs( argc, argv, &x, &y, NULL, NULL );
- while( --argc ){
- if( **++argv == '-' ){
- switch( *++*argv|0x20 ){
- case 'a':
- autoexit= TRUE;
- break;
- case 'b':
- batch= TRUE;
- break;
- case 'r':
- switch( *++*argv|0x20 ){
- case 'x':
- case 's': /* -rsum */
- rettype= 0;
- break;
- case 'y':
- case 'c': /* -rcrc */
- rettype= 1;
- break;
- case 'g':
- rettype= 2;
- break;
- }
- break;
- case 's':
- sendflag= TRUE;
- switch( *++*argv|0x20 ){
- case 'x': /* 128 */
- rettype= 0;
- break;
- case 'l':
- rettype= 1;
- break;
- case 'y':
- rettype= 2;
- break;
- }
- break;
- case 'd':
- if( *++*argv == 'd' ){
- extern unsigned char downdir[];
- strcpy( downdir, (*argv)+1 );
- }
- break;
- }
- }else
- strcpy( filename, *argv );
- }
- WindowTitleOpen( x, y, SIZEH, SIZEV, NULL, "KoPro 1.16", Close|Push, Exec );
- }
-